package org.example.hypersonaltools.sqlite;

import lombok.Getter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

@Getter
public class SqliteExample {
    public Connection connection = null;
    public SqliteExample(String dbName){
        try {
            // 加载SQLite JDBC驱动
            Class.forName("org.sqlite.JDBC");
            // 连接到SQLite数据库（如果数据库不存在，则会自动创建）
            connection = DriverManager.getConnection("jdbc:sqlite:"+dbName+".db");
            System.out.println("成功连接到SQLite数据库。");
        } catch (ClassNotFoundException e) {
            System.out.println("找不到SQLite JDBC驱动类。");
            e.printStackTrace();
        } catch (SQLException e) {
            System.out.println("连接SQLite数据库时发生错误。");
            e.printStackTrace();
        }
    }
}